<?php

        $dbhost = "localhost";
        $dbuser = "ic2010020245";
        $dbpassword = "ic2010020245";
        $dbname = "ic2010020245";

	$conexion=mysql_connect($dbhost,$dbuser,$dbpassword);
	mysql_select_db($dbname,$conexion);

//$x=$_POST['tablas'];
//echo "recibe tablas:".$x."<br>";
$tabla=$_POST['tablas'];//Alumno;
	$consulta="DESCRIBE ".$tabla;
	$res=mysql_query($consulta,$conexion)or die(mysql_error());
        
while($Rs2 = mysql_fetch_array($res))
 {
   $cad1[]=$Rs2['Field'];
$cad2[]=$Rs2['Type'];
}
/*
for($i=0;$i<sizeof($cad1);$i++)
{
 echo "Field:".$cad1[$i]."<br>";
 echo "Type:".$cad2[$i]."<br>";
 if($cad2[$i]=="int(11)")
  echo"ENTRO";//si entra

$cadena = "Sin León no hubiera España";
$buscar = "León";
$resultado = strpos($cadena, $buscar);

if($resultado !== FALSE){
    echo "La subcadena '$buscar' fue encontrada dentro de la cadena '$cadena' en la posición: '$resultado'";
}
}
*/


echo"<!DOCTYPE html>";
echo"<html>";
echo" <head><title>Tabla</title></head>";
echo" <body>";
echo"<form  action=\"Busqueda.php\" method=POST>";


echo"<center>";

echo"<table>";
echo"<tr>";
echo"<td>Atributo</td>";
echo"<td>Tipo de dato</td>";
echo"<td>Operador</td>";
echo"<td>Valor</td>";
echo"</tr>";

$tam=sizeof($cad1);
echo"<input type=\"hidden\" name=\"Tamanio\" value=".$tam." class=\"boton\"></input>";
echo"<input type=\"hidden\" name=\"Tabla\" value=\"".$tabla."\" class=\"boton\"></input>";


for($i=0;$i<$tam;$i++)
{
  echo"<tr>";
   echo "<td>".$cad1[$i]."</td>";
   echo "<td>".$cad2[$i]."</td>";
echo "<td>";

$str=$cad2[$i];
$buscar="varchar";
$isVarchar = strpos($str, $buscar);
   if($str=="text" OR $isVarchar)
   {
    echo "<select name=".$cad1[$i]."LIST size=\"0\">";
     echo "<option value=\"Like\">Like</option>";
     echo "<option value=\"Like %..%\">Like %..%</option>";
     echo "<option value=\"Igual\">=</option>";
     echo "<option value=\"Diferente\">!=</option>";
    echo "</select>";
   }
   else
   {
    echo "<select name=".$cad1[$i]."LIST size=\"0\">";
     echo "<option value=\"Menor\"><</option>";
     echo "<option value=\"Mayor\">></option>";
     echo "<option value=\"MenorI\"><=</option>";
     echo "<option value=\"MayorI\">>=</option>";
     echo "<option value=\"Igual\">=</option>";
     echo "<option value=\"Diferente\">!=</option>";
    echo "</select>";
    
   }
echo "</td>";
echo "<td><input type=\"text\" name=\"".$cad1[$i]."\" value=\"\"></td>";
   echo"</tr>";
}
echo"</table>";


echo"<input type=\"submit\" value=\"Buscar\"/>";echo"</center>";
echo"</body>";
echo"</html>";
?>